package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.OaAdminCar;
import com.ruoyi.oa.domain.vo.OaAdminCarVo;
import com.ruoyi.oa.domain.bo.OaAdminCarBo;
import com.ruoyi.oa.service.IOaAdminCarService;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.oa.domain.vo.OaProjectVo;


/**
 * 公车使用申请
 *
 * @author ruoyi
 * @date 2023-08-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/adminCar")
public class OaAdminCarController extends BaseController {

    private final IOaAdminCarService iOaAdminCarService;

    /**
     * 查询公车使用申请列表
     */
//    @SaCheckPermission("oa:adminCar:list")
    @GetMapping("/list")
    public TableDataInfo<OaAdminCarVo> list(OaAdminCarBo bo, PageQuery pageQuery) {
        return iOaAdminCarService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出公车使用申请列表
     */
//    @SaCheckPermission("oa:adminCar:export")
    @Log(title = "公车使用申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OaAdminCarBo bo, HttpServletResponse response) {
        List<OaAdminCarVo> list = iOaAdminCarService.queryList(bo);
        ExcelUtil.exportExcel(list, "公车使用申请", OaAdminCarVo.class, response);
    }

    /**
     * 获取公车使用申请详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("oa:adminCar:query")
    @GetMapping("/{id}")
    public R<OaAdminCarVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iOaAdminCarService.queryById(id));
    }

    /**
     * 新增公车使用申请
     */
//    @SaCheckPermission("oa:adminCar:add")
    @Log(title = "公车使用申请", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<OaAdminCarBo> add(@Validated(AddGroup.class) @RequestBody OaAdminCarBo bo) {
        return R.ok(iOaAdminCarService.insertByBo(bo));
    }

    /**
     * 修改公车使用申请
     */
//    @SaCheckPermission("oa:adminCar:edit")
    @Log(title = "公车使用申请", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<OaAdminCar> edit(@Validated(EditGroup.class) @RequestBody OaAdminCarBo bo) {
        return R.ok(iOaAdminCarService.updateByBo(bo));
    }

    /**
     * 删除公车使用申请
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("oa:adminCar:remove")
    @Log(title = "公车使用申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iOaAdminCarService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
